package cn.wechat.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.wechat.pojo.user.Goods;
import cn.wechat.pojo.user.User;
import cn.wechat.service.user.UserService;
import cn.wechat.tools.Constants;

@Controller
@RequestMapping(value = "/user")
public class UserController {

	@Resource(name = "userService")
	public UserService userService;

	@RequestMapping(value = "/login.html")
	private String login() {
		return "sign";
	}
	@RequestMapping(value = "/index.html")
	private String index() {
		return "index";
	}
	@RequestMapping(value = "/all.html")
	private String all() {
		return "all";
	}
	@RequestMapping(value = "/myMessage.html")
	private String myMessage() {
		return "myMessage";
	}
	@RequestMapping(value = "/resetpwd.html")
	private String resetpwd() {
		return "resetpwd";
	}
	@RequestMapping(value = "/search.html")
	private String search() {
		return "search";
	}
	@RequestMapping(value = "/shopCar.html")
	private String shopCar() {
		return "shopCar";
	}
	@RequestMapping(value = "/xiangqing.html")
	private String xiangqing() {
		return "xiangqing";
	}
	
	@RequestMapping(value = "/doLogin.html")
	public String DoLogin(@RequestParam("usercode") String userCode,
			@RequestParam("password") String userPassword,
			HttpSession session) {
		User user=userService.login(userCode, userPassword);
		if(user!=null){
			System.out.println("登陆成功！");
			session.setAttribute(Constants.USER_SESSION, user);	//存進Session對象
			return "index";
		}
		System.out.println("登陆失败！");
		return "sign";
	}


}
